<script type="text/javascript">
$(function(){
	var pg = App.deploy.planEdit.ui, pp = pg.params || {};

	var frm = {
		name: pg.seek('name'),
		code: pg.seek('code'),
		onlineTime: pg.seek('onlineTime'),
		packCode: pg.seek('packCode'),
		deployCode: pg.seek('deployCode'),
		memo: pg.seek('memo'),
		packServer: pg.seek('packServer')
	};
	function getValues(){
		return {
			id: pp.id,
 			projId: pp.projId,
			name: frm.name.val(),
			code: frm.code.val(),
			onlineTime: frm.onlineTime.val(),
			packCode: frm.packCode.val(),
			deployCode: frm.deployCode.val(),
			memo: frm.memo.val(),
			packServer: frm.packServer.val()
		};
	}
	function setValues(o){
		frm.name.val(o.name);
		frm.code.val(o.code);
		frm.onlineTime.val(o.onlineTime);
		frm.packCode.val(o.packCode),
		frm.deployCode.val(o.deployCode),
		frm.memo.val(o.memo);
		frm.packServer.val(o.packServer);
	}
	function validate(p){
		var msg=pg.seek('msg');
		msg.html('');
		var x = App.validate, v = App.deploy.validator, va = App.base.validation;

		return x(v.plan.name, p.name, msg, '名字') &&
			x(v.plan.code, p.code, msg, '编号') &&
// 			x(v.plan.packCode, p.packCode, msg, '打包构建码')
// 			x(v.plan.deployCode, p.deployCode, msg, '部署发布码')
			x(v.plan.packServer, p.packServer, msg, '打包服务器地址');
	}
	
	frm.onlineTime.datepicker({
		prevText: "<上一月",
		nextText: "下一月>",
		dateFormat: "yy-mm-dd",
		changeMonth: true,
		changeYear: true,
		inline: true
	});
	pg.find('input').blur(function(){
		var pms = getValues();
		if(!validate(pms))
			return;
	});
	pg.seek('next').click(function(){
		w = mac.wait('Loading');
		var pms = getValues();

		if(!validate(pms)){
			w.close();
			return;
		}
		$.post(App.deploy.ctx + '/plan/save.do', pms, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				pg.callback(ro.data, 2);//更新树
				w.close();
				pg.close();
			} else {
				w.close();
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	
	pg.seek('ok').click(function(){
		var pms = getValues();
		if (!validate(pms))
			return;
		$.post(App.deploy.ctx + '/plan/save.do', pms, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				pg.callback(ro.data, 1);
				pg.close();
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return true;
	});
	pg.seek('close').click(function(){
		pg.close();
	})
	
	if (pp.id) {
		var w = mac.wait('Loading');
		$.get(App.deploy.ctx + '/plan/get.do', {
			id: pp.id
		}, function(rs) {
			var ro = mac.eval(rs);
			if (ro.success) {
				setValues(ro.data);
			} else {
 				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
			w.close();
		});
	} else {
		setValues(pp);
	}
});
</script>
<div class="form">
	<div class="item">
		<span class="label">编号</span>
		<input type="text" name="code" placeholder="请填入部署计划编号" />
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">名字</span>
		<input type="text" name="name" placeholder="请填入部署计划中文名" />
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">打包构建</span>
		<input type="text" name="packCode" placeholder="请填入源码构建" />
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">部署发布</span>
		<input type="text" name="deployCode" placeholder="部署发布构建" />
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">计划上线时间</span>
		<input type="text" name="onlineTime" placeholder="请填入部署计划执行时间" />
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">打包服务器</span>
		<input type="text" name="packServer" placeholder="请填入打包服务器的地址（IP:PORT）" />
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">备注</span>
		<textarea name="memo" placeholder="请填入备注"></textarea>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">&nbsp;</span>
		<div name="msg" class="msg"></div>
		<div class="clear"></div>
	</div>
	<div class="bottom">
		<button name="ok">确定</button>
		<button name="next">下一步</button>
		<button name="close">取消</button>
	</div>
</div>